/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 运行时;

import org.junit.Test;

import java.util.Date;
import java.util.Scanner;

/**
 * @description RuntimeException 运行时异常
 * @author 俊昭
 * @date 2022/4/10
*/
public class RuntimeExceptionTest {
    // 空指针 NullPointerException
    @Test
    public void test01(){
        int[] arr = null;
        System.out.println(arr[3]);

        String str = null;
        System.out.println(str.charAt(0));

    }

    // 角标越界 IndexOutOfBoundsException
    @Test
    public void test02(){
        int[] arr = new int[3];
        System.out.println(arr[3]);// 数组的

        String str = "01234";
        System.out.println(str.charAt(5));// 字符串的

    }

    // 类型转换 ClassCastException
    @Test
    public void test03(){
        Object obj = new Date();
        String str = (String) obj;
    }

    // 数字格式 NumberFormatException
    @Test
    public void test04(){
        String str = "abc";
        int a = Integer.parseInt(str);
    }

    // 输入不匹配 InputMismatchException
    @Test
    public void test05(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt('q');
        System.out.println(a);
    }

    // 算术 ArithmeticException
    @Test
    public void test06(){
        System.out.println(2/0);
    }

    // 算术 ArithmeticException
    @Test
    public void test07(){

    }

}
